
/////
//Advocates For Hire: 
//How Government Contracting Shapes Politics 
//Governance
//Leslie K. Finger (University of North Texas)
//Carlos X. Lastra-Anadón (IE University)

////Code for producing  tables and figures from main body of article
//Appendix data and code available upon request from clastra@faculty.ie.edu
////


use "~/20200108 TFAdata.dta"
cd "/Users/carlosxabel/Dropbox/TFA proposal/Final files"

ssc install estout


**** Table 1 (First Stage)

local controls nominate nearate povrate postobama2009
  eststo clear

reg tfa     classsizelaw1lag  `controls' i.stateno if year<2015, r
  eststo 

esttab using "tables.rtf",      ///
	se r2 star(* 0.05 ** 0.01 *** 0.001) scalars(F) ///
	drop ( _cons  nominate nearate povrate postobama2009 ) nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Robust standard errors in parentheses.") ///
	noconstant indicate("State Fixed Effects = *stateno")

	
	
*****Figure 4
local controls povrate   nominate nearate   i.stateno postobama2009
eststo clear
quietly reg groupsarrive tfa2lag    `controls'  , cluster(stateno)
estimates store estgroups1OLS
quietly reg chgroupsarrive tfa2lag    `controls'  , cluster(stateno)
estimates store estgroups2OLS
quietly reg gengroupsarrive tfa2lag    `controls'  , cluster(stateno)
estimates store estgroups3OLS
quietly reg neachange tfa2lag    `controls', cluster(stateno)
estimates store estgroups4OLS

esttab estgroups1OLS  estgroups2OLS estgroups3OLS estgroups4OLS , ///
	title("Binary variable post-reform")   noconstant ///
	se l  drop(_cons) append nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")
	



local controls povrate   nominate nearate   i.stateno postobama2009
local iv tfa2lag = classsizelaw3lag ptratio3lag
quietly ivregress 2sls groupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups1IV
quietly ivregress 2sls  chgroupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups2IV
quietly ivregress 2sls gengroupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups3IV
quietly ivregress 2sls neachange (`iv') `controls', cluster(stateno)
estimates store estgroups4IV

esttab estgroups1IV  estgroups2IV , ///
	title("Binary variable post-reform")   noconstant ///
	se l  drop(_cons) append nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")
	


local controls povrate   nominate nearate   i.stateno 
local iv tfa2lag = classsizelaw3lag ptratio3lag
quietly ivregress 2sls groupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups1IV2
quietly ivregress 2sls  chgroupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups2IV2
quietly ivregress 2sls gengroupsarrive (`iv') `controls'  , cluster(stateno)
estimates store estgroups3IV2
quietly ivregress 2sls neachange (`iv') `controls', cluster(stateno)
estimates store estgroups4IV2

esttab estgroups1IV2  estgroups2IV2 , ///
	title("Binary variable post-reform")   noconstant ///
	se l  drop(_cons) append nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")
	

coefplot (estgroups1OLS	, msymbol(X) label("OLS")) (estgroups1IV, msymbol(smv) label("2SLS with Post-Obama Dummy")) ///
 (estgroups1IV2, msymbol(plus) label("2SLS no Post-Obama")), bylabel("Arrival of Any Ed Reform Group") || ///
(estgroups2OLS, msymbol(X) label("OLS")) (estgroups2IV, msymbol(smv) label("2SLS with Post-Obama Dummy")) ///
 (estgroups2IV2, msymbol(plus) label("2SLS no Post-Obama")), bylabel("Arrival of School Choice Group")||  ///
(estgroups3OLS, msymbol(X) label("OLS")) (estgroups3IV, msymbol(smv) label("2SLS with Post-Obama Dummy"))  ///
(estgroups3IV2, msymbol(plus) label("2SLS no Post-Obama")), bylabel("Arrival of General Ed Reform Group") ||  ///
(estgroups4OLS, msymbol(X) label("OLS")) (estgroups4IV, msymbol(smv) label("2SLS with Post-Obama Dummy")) ///
 (estgroups4IV2, msymbol(plus) label("2SLS no Post-Obama")),  bylabel("Change in NEA Membership Rate")  ///
drop(_cons povrate nominate nearate *stateno postobama2009)  ///
 yline(0) levels(95) bycoefs   vertical bylabels( , wrap(20)) ylabels(,labsize(large)) ///
  msize(large) legend(col(3) size(vlarge)) graphregion( margin(small))  xsize(9) coeflabels(,labsize(vlarge))
 
graph export "/Users/Leslie/Dropbox/Papers/Co-authoring/Work with Carlos/TFA Paper/Data and analyses/current data/Groups Results_all.pdf", replace



********Figure 5


//replace adjspendingpp = adjspendingpp/1000
//replace perccharters = perccharters*100
local controls  povrate   nominate nearate  i.stateno postobama2009

eststo clear
quietly reg  charterchange  tfa2lag `controls'  , cluster(stateno)
estimates store est1OLS
quietly reg  perccharters  tfa2lag `controls'  , cluster(stateno)
estimates store est2OLS
quietly reg  voucherpass  tfa2lag `controls'  , cluster(stateno)
estimates store est3OLS
quietly reg  tenrepeal  tfa2lag `controls'  , cluster(stateno)
estimates store est4OLS
quietly reg  perfpaypass  tfa2lag `controls'  , cluster(stateno)
estimates store est5OLS
*quietly reg  adjspendingpp  tfa2lag `controls'  , cluster(stateno)
*estimates store est6OLS
esttab est1OLS est2OLS est3OLS est4OLS est5OLS ,   /// 
	se star(* 0.05 ** 0.01 *** 0.001) ///
	drop ( _cons) nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")


local controls  povrate    nearate  i.stateno postobama2009 
local iv tfa2lag=classsizelaw3lag ptratio3lag 
*IV models (with postObama)
quietly ivregress 2sls  charterchange  (`iv') `controls'  , cluster(stateno)
estimates store est1IV 
quietly ivregress 2sls  perccharters  (`iv') `controls'  , cluster(stateno)
estimates store est2IV
quietly ivregress 2sls  voucherpass  (`iv') `controls'  , cluster(stateno)
estimates store est3IV
quietly ivregress 2sls  tenrepeal  (`iv') `controls'  , cluster(stateno)
estimates store est4IV
quietly ivregress 2sls  perfpaypass  (`iv') `controls'  , cluster(stateno)
estimates store est5IV
*quietly ivregress 2sls  adjspendingpp  (`iv') `controls'  , cluster(stateno)
*estimates store est6IV
esttab est1IV est2IV est3IV est4IV est5IV  ,   /// 
	se star(* 0.05 ** 0.01 *** 0.001) ///
	drop ( _cons) nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")

	
local controls  povrate   nominate nearate  i.stateno 
local iv tfa2lag=classsizelaw3lag ptratio3lag 
*IV models (with no postObama)
quietly ivregress 2sls  charterchange  (`iv') `controls'  , cluster(stateno)
estimates store est1IV2
quietly ivregress 2sls  perccharters  (`iv') `controls'  , cluster(stateno)
estimates store est2IV2
quietly ivregress 2sls  voucherpass  (`iv') `controls'  , cluster(stateno)
estimates store est3IV2
quietly ivregress 2sls  tenrepeal  (`iv') `controls'  , cluster(stateno)
estimates store est4IV2
quietly ivregress 2sls  perfpaypass  (`iv') `controls'  , cluster(stateno)
estimates store est5IV2
*quietly ivregress 2sls  adjspendingpp  (`iv') `controls'  , cluster(stateno)
*estimates store est6IV2
esttab est1IV2 est2IV2 est3IV2 est4IV2 est5IV2 ,   /// 
	se star(* 0.05 ** 0.01 *** 0.001) ///
	drop ( _cons) nonotes ///
	addnotes("\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)" "Standards errors clustered by state in parentheses.") indicate("State Fixed Effects = *stateno")

	
coefplot (est1OLS, msymbol(X) label("OLS")) (est1IV, msymbol(smv) label("2SLS with Post-Obama Dummy")) ///
(est1IV2, msymbol(smplus) label("2SLS no Post-Obama")), bylabel("Charter Law Passed") || ///
(est3OLS, msymbol(X)) (est3IV, msymbol(smv)) (est3IV2, msymbol(plus) ///
 label("2SLS no Post-Obama")),  bylabel("Private School Choice Passed") || ///
(est4OLS, msymbol(X)) (est4IV, msymbol(smv)) (est4IV2, msymbol(plus) ///
label("2SLS no Post-Obama")), bylabel("Automatic Tenure Repealed") || ///
(est5OLS, msymbol(X)) (est5IV, msymbol(smv)) (est5IV2, msymbol(plus) ///
 label("2SLS no Post-Obama")), bylabel("Performance Pay Passed") ///
drop(_cons povrate nominate nearate *stateno postobama2009)  vertical  ///
 yline(0) levels(95) bycoefs  legend(size(medsmall) rows(1)) yscale(range(-.15 1.05)) /// 
 ylabel(0(.5) 1) bylabels( , wrap(15)) coeflabels(,labsize(large)) ///
 msize(large)   graphregion( margin(zero)) ylabels(,labsize(medlarge))
graph save graph1, replace
 
coefplot (est2OLS, msymbol(X)) (est2IV, msymbol(smv)) (est2IV2, msymbol(plus) ///
label("2SLS no Post-Obama")), bylabel("Charter Share of Public Schools")  ///
drop(_cons povrate nominate nearate *stateno postobama2009) bylabels( ) ///
 yline(0) levels(95) bycoefs   vertical coeflabels(,labsize(large)) ///
 msize(large) graphregion( margin(zero)) ylabels(,labsize(medlarge))
graph save graph2, replace
display graph1
grc1leg  graph1.gph graph2.gph , ///
	legendfrom(graph1.gph) col(2)   
	
	
graph export "/Users/Leslie/Dropbox/Papers/Co-authoring/Work with Carlos/TFA Paper/Data and analyses/current data/Policy Results.pdf", replace


**Mediation analysis Table 3

global controlsstate povrate   nominate nearate i.stateno 


*IV
eststo clear
global iv tfa2lag = classsizelaw3lag 
 global depgroupvariables groupsarrive chgroupsarrive gengroupsarrive neachange pubmemchange
 global edreformvariables charterchange perccharters voucherpass tenrepeal perfpaypass 
 
 
 eststo clear
foreach  var of global edreformvariables{
quietly ivregress 2sls  `var'  ($iv) 	groupsarrive $controlsstate  , cluster(stateno)
eststo
}

esttab using "MediationReformvariablesGrouparrival.rtf", ///
	title("Binary variable post-reform")   noconstant ///
	se l  drop(_cons *stateno) append nonotes ///
	addnotes("Cluster standard errors in parentheses.") 

 
 *OLS
 eststo clear
foreach  var of global edreformvariables{
quietly reg  `var'  tfa2lag	groupsarrive $controlsstate  , cluster(stateno)
eststo
}

esttab using "MediationReformvariablesGrouparrivalOLS.rtf", ///
	title("Binary variable post-reform")   noconstant ///
	se l  drop(_cons *stateno) replace nonotes ///
	addnotes("Cluster standard errors in parentheses.") 
	
	
	

